/**
 * @param {arr} x
 * @return {targe}
 */

function getIndex(arr,number){
    var st = 0;
        len = arr.length,
        end = len-1;
    while(st<=end){
    var targe = Math.floor((st+end)/2); //利用开头和结尾
    if(number==arr[targe]){
        return targe;
    }else if(number>arr[targe]){
        st = targe+1;  //当值大于时，说明取后半段，开头str向前移
    }else{
        end = targe-1; //当值大于时，说明取前半段，尾部end向前移
    }
    }
    return arr;
}

var arr = [1,2,2,4,5,5,5,6,7,8,9,10];
console.log(getIndex(arr,7))